/*
 * @Date: 2025-06-13 10:50:10
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-09-27 23:49:25
 * @FilePath: \corpus\src\pages\resourceManagement\fileList\component\ExportFile\index.tsx
 */
import UploadCorpusMuplte from '@/components/UploadCorpusMuplte';
import { useLocation } from '@umijs/max';
import { Form, Modal, Radio } from 'antd';
import type React from 'react';
import { useEffect, useState } from 'react';
import hooks from '../../hooks';
const EditAngent: React.FC = () => {
  const {
    setExportFileVisible,
    getNewListContent,
    addResourceFileContent,
    newList,
    exportFileVisible,
    exportFile,
    setNewList,
  } = hooks.useContainer();

  const location: Record<string, any> = useLocation();

  const val = location?.state?.val ? location?.state?.val : '';
  const title = '批量导入';

  const handleSubmit = () => {
    exportFile.validateFields().then((vals) => {
      const method = addResourceFileContent;
      method.run({
        ...vals,
      });
    });
  };

  const [falg, setFalg] = useState<boolean>(false);
  useEffect(() => {
    if (!exportFileVisible) {
      setNewList([]);
      exportFile.resetFields();
    } else {
      getNewListContent.run({
        openProperty: val,
        current: 1,
        pageSize: 100,
      });
    }
  }, [exportFileVisible]);
  return (
    <Modal
      width={600}
      title={title}
      open={exportFileVisible}
      onCancel={() => {
        exportFile.resetFields();
        setExportFileVisible(false);
      }}
      onOk={handleSubmit}
      confirmLoading={addResourceFileContent.loading}
    >
      <Form labelCol={{ span: 4 }} form={exportFile}>
        <Form.Item name="id" hidden />

        {/* <Form.Item
          label={'选中知识库'}
          name="knowledgeId"
          rules={[{ required: falg, message: '请选择' }]}
        >
          <Select
            style={{ width: '100% ' }}
            placeholder="请选择"
            fieldNames={{ label: 'name', value: 'id' }}
            options={newList}
            disabled={!falg}
          />
        </Form.Item> */}

        <Form.Item
          label={`是否解析`}
          name="needParse"
          rules={[{ required: true, message: '请选择' }]}
        >
          <Radio.Group
            onChange={(val) => {
              // setFalg(val.target.value);
              if (!val.target.value) {
                exportFile.setFieldValue('knowledgeId', '');
              }
              exportFile.setFieldValue('needParse', val.target.value);
            }}
            options={[
              { label: '立即解析', value: true },
              { label: '暂缓解析', value: false },
            ]}
          />
        </Form.Item>

        <Form.Item label={`上传`} name="files" rules={[{ required: true, message: '请选择' }]}>
          <UploadCorpusMuplte
            action="/corpus/common/filesUpdate"
            multiple={true}
            handleChange={({ fileList }) => {
              console.log(fileList);
              const arr = fileList.map((item) => {
                return { ...item.response?.data[0] };
              });
              exportFile.setFieldValue('files', arr);
              console.log(arr);
            }}
          />
        </Form.Item>
        <Form.Item label={''} name="" rules={[{ required: false, message: '请选择' }]}>
          <p style={{ padding: '20.0px', color: 'gray' }}>
            文本解析支持的文档类型：doc、docx、pdf、txt 批量上传总数不超过100个，累计大小不超过1.5G
          </p>
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default EditAngent;
